<?php

namespace App\Trip\Traits\TimeTraits;

use Carbon\Carbon;
use Exception;

trait ArriveDateTimeTrait
{
    use DateTimeTrait;


    public function getArriveDate(): string
    {
        return $this->getArriveAt() ? Carbon::parse($this->getArriveAt())->toDateString() : '';
    }

    /**
     * 到达时间
     * @return string
     */
    public function getArriveAt(): string
    {
        return $this->arrive_at ?: '';
    }

    public function getArriveTime(): string
    {
        return Carbon::parse($this->getArriveAt())->format("H:i");
    }

    /**
     * @throws Exception
     */
    public function setArriveAt(string $arrive_at): void
    {
        if (!$this->isDatetime($arrive_at)) {
            throw new Exception('日期格式错误');
        }
        $this->arrive_at = $arrive_at;
    }


}